package org.springblade.tms.module.exceptioncosttype.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.tms.module.exceptioncosttype.base.ExceptionMoldTypeService;
import org.springblade.tms.module.exceptioncosttype.entity.TMExceptionCostType;
import org.springblade.tms.module.exceptioncosttype.service.IExceptionCostTypeService;
import org.springblade.tms.module.exceptioncosttype.vo.CostType;
import org.springblade.tms.module.exceptioncosttype.vo.TMExceptionCostTypeVO;
import org.springblade.tms.module.exceptioncosttype.wrapper.ExceptionCostTypeWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.exceptioncosttype.controller
 * @className: ExceptionMoldTypeController
 * @author: yr
 * @description: 费用类型接口
 * @date: 2022/4/20 17:00
 */
@RestController
@RequestMapping("exceptioncosttype/exceptionMoldType")
@Api(value = "异常费用类型-yr", tags = "异常费用类型接口-yr")
public class ExceptionMoldTypeController {
	@Resource
	private IExceptionCostTypeService exceptionCostTypeService;
	@Resource
	private ExceptionMoldTypeService exceptionMoldTypeService;
	/**
	 * 分页 异常费用类型
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "列表查询", notes = "传入exceptionCostType")
	public R<IPage<CostType>> list(TMExceptionCostType TMExceptionCostType, Query query) {
		return exceptionMoldTypeService.list(TMExceptionCostType,query);
	}

	/**
	 * 分页 异常费用类型
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "费用类型", notes = "传入orderType")
	public R<List<TMExceptionCostTypeVO>> detail(@ApiParam(value = "运单类型", required = true)@RequestParam String orderType) {
		List<TMExceptionCostType> exceptionCostTypeList = exceptionCostTypeService.lambdaQuery().eq(TMExceptionCostType::getOrderType, orderType).list();
		return R.data(ExceptionCostTypeWrapper.build().listVO(exceptionCostTypeList));
	}


	/**
	 * 新增或修改 异常类型
	 */
	@ApiLog("新增或修改异常类型")
	@PostMapping("/saveOrUpdate")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "新增或修改异常类型", notes = "传入exceptionType")
	public R saveOrUpdate(@Valid @RequestBody List<TMExceptionCostTypeVO> exceptionCostTypes) {
		return exceptionMoldTypeService.saveOrUpdate(exceptionCostTypes);
	}
}
